package com.boxin.ims.modules.wechat.busi;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.boxin.ims.modules.wechat.entity.LotteryRecord;
import com.boxin.ims.modules.wechat.entity.WechatMember;
import com.boxin.ims.modules.wechat.entity.dic.Storefront;
import com.boxin.ims.modules.wechat.service.LotteryRecordService;
import com.boxin.ims.modules.wechat.service.dic.StorefrontService;

/**
 * @author Jakemanse
 * @date 2013-12-11
 * @function <p> 核销 注册会员时获取的奖品 </p>
 */
@Service
public class DeleteRegLotteryProcessor extends BusinessProcessor {

	@Autowired
	private StorefrontService storefrontService ;
	
	@Autowired
	private LotteryRecordService lotteryRecordService;
	
	
	@Override
	public ProcessMessage process() {
		WechatMember member = memberCheckAndReply();
		if(member!=null){
			String keyword = getTextMessage().getContent();
			Storefront storefront = storefrontService.getByCommand(keyword);
			String reply = "核销成功,谢谢!";
			if(storefront != null){
				
				String remarks = "此礼品已由【"+storefront.getAddress()+"】核销.";
				int n = lotteryRecordService.updateRegLotteryStatus(user.getId(),member.getId(),remarks);
				if(n == 1){//核销成功
					
				}else{
					LotteryRecord lotteryRecord =	lotteryRecordService.getRegLotteryByUserIdMemberId(user.getId(), member.getId());
					if(lotteryRecord == null){
						reply ="对不起,未找到您的奖品信息.";
					}else{
						if(LotteryRecord.STATUS_CLEAR.equals(lotteryRecord.getStatus())){
							reply ="对不起,您的奖品【"+lotteryRecord.getName()+"】已被'"+storefront.getAddress()+"'核销过,不能再重复使用,谢谢！";
						}else if(LotteryRecord.STATUS_DROP.equals(lotteryRecord.getStatus())){
							reply ="对不起,您的奖品【"+lotteryRecord.getName()+"】已作废!";
						}
					}
				}
			}else{
				reply = "对不起,您输入的指令'"+keyword+"'无法找到匹配的实体店.";
			}
			
			
			writeToUser(reply);
			
		}
		
		return null;
	}

	@Override
	public boolean isNeedBeMember() {
		
		return false;
	}
	
	

}
